package com.zyx.javademo.exception;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author Yaxi.Zhang
 * @since 2021/9/28 18:03
 * desc: 线程池submit中提交任务失败案例
 * reference: https://honeypps.com/java/java-multi-thread-of-uncaught-exception-handler/
 * 只有通过execute提交的任务, 才能将它抛出的异常交给UncaughtExceptionHandler,
 * 而通过submit提交的任务, 无论是抛出的未检测异常还是已检查异常, 都将被认为是任务返回状态的一部分
 * 如果一个由submit提交的任务由于抛出了异常而结束, 那么这个异常将被Future.get封装在ExecutionException中重新抛出
 */
public class SubmitCaught {
    public static void main(String[] args) {
        ExecutorService exec = Executors.newCachedThreadPool();
        exec.submit(new ThreadPoolTask());
        exec.shutdown();
    }
}
